{extend name="Public:base" /}
{block name="main"}
<main>
	<!-- breadcrumb-area-start -->
	<!-- <section class="breadcrumb-area" data-background="img/bg/page-title.png">
		<div class="container">
			<div class="row">
				<div class="col-xl-12">
					<div class="breadcrumb-text text-center">
						<h1>Shoping Cart</h1>
						<ul class="breadcrumb-menu">
							<li><a href="index.html">home</a></li>
							<li><span>Cart</span></li>
						</ul>
					</div>
				</div>
			</div>
		</div>
	</section>
	 --><!-- breadcrumb-area-end -->

	<!-- Cart Area Strat-->
	<section class="cart-area pt-100 pb-100">
		<div class="container">
			<div class="row">
				<div class="col-12">
					<form action="#">
						<div class="table-content table-responsive">
							<table class="table">
								<thead>
									<tr>
										<th class="product-thumbnail">Images</th>
										<th class="cart-product-name">Product</th>
										<th class="product-price">Unit Price</th>
										<th class="product-quantity">Quantity</th>
										<th class="product-subtotal">Total</th>
										<th class="product-remove">Remove</th>
									</tr>
								</thead>
								<tbody id="table-add">
								</tbody>
							</table>
						</div>
						<div class="row">
							<div class="col-12">
								<div class="coupon-all">
									<!-- <div class="coupon">
										<input id="coupon_code" class="input-text" name="coupon_code" value=""
											placeholder="Coupon code" type="text">
										<button class="btn theme-btn-2" name="apply_coupon" type="submit">Apply
											coupon</button>
									</div> -->
									<div class="coupon2">
										<input class="btn theme-btn" name="update_cart" value="Update cart"
											type="submit">
									</div>
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-md-5 ml-auto">
								<div class="cart-page-total">
									<h2>Cart totals</h2>
									<ul class="mb-20">
										<li>Subtotal <span id="Subtotal">$0.00</span></li>
										<li>Shipping <span id="Freight">$0.00</span></li>
										<li>Total <span id="Total">$0.00</span></li>
									</ul>
									<a class="btn theme-btn" href="/index/checkout.html">Proceed to checkout</a>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
	</section>
	<!-- Cart Area End-->
</main>
{/block}
{block name="script"}
<script>
	window.onload = function() {
		getCartList();
	}

	function onLoad() {
		if ($.cookie("token")) {
			if ($.cookie("is_wholesale") == 1) {
				$("#wholesale").css('display', 'block');
				$("#login").css('display', 'none');
			}
		}
	}

	//获取购物车列表
	function getCartList() {
		let ajax = new Services();
		var data = {}
		ajax.postExample("/index/order/shoppingCart", data,
			function(res) {
				if (res.code == 200) {
					let is_wholesale = $.cookie('is_wholesale')
					obj = {
						is_wholesale:$.cookie('is_wholesale'),
						list:res.data.order_goods_list
					}
					if(is_wholesale == 1) {
						var html = template('cartList1', obj) //通过模板的id,将数据和和模板绑定,并用一个变量接收
					}else {
						var html = template('cartList', obj) //通过模板的id,将数据和和模板绑定,并用一个变量接收
					}
					$('#table-add').html(html)
					$('#Subtotal').html(res.data.order.sub_money)
					$('#Freight').html(res.data.order.delivery_money)
					$('#Total').html(res.data.order.money)
				} else {
					//错误提示
					TS.errorAlert(res.error);
				}
			},
			function(e) {
				console.log("222", e);
			}
		)
	}
</script>
<script type="text/html" id="cartList">
{{each list item index}}
<tr>
	<td class="product-thumbnail"><a href="#"><img src="{{item.icon}}" alt=""></a></td>
	<td class="product-name"><a href="#">{{item.name}}</a></td>
	<td class="product-price"><span class="amount">{{item.price}}</span></td>
	<td class="product-quantity">
		<div class="cart-plus-minus"><input type="text" value="{{item.num}}" /></div>
	</td>
	<td class="product-subtotal"><span class="amount">{{item.money}}</span></td>
	<td class="product-remove"><a href="#"><i class="fa fa-times"></i></a></td>
</tr>
{{/each}}
</script>
<script type="text/html" id="cartList1">
{{each list item index}}
<tr>
	<td class="product-thumbnail"><a href="#"><img src="{{item.icon}}" alt=""></a></td>
	<td class="product-name"><a href="#">{{item.name}}</a></td>
	<td class="product-price"><span class="amount">{{item.price}}</span></td>
	<td class="product-quantity">
		<div class="cart-plus-minus"><input type="text" value="{{item.num}}" /></div>
	</td>
	<td class="product-subtotal"><span class="amount">{{item.money}}</span></td>
	<td class="product-remove"><a href="#"><i class="fa fa-times"></i></a></td>
</tr>
{{/each}}
</script>
{/block}
